<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    </style>
</head>

<body>
    <div id="app">
        <p>
            <input type="text" v-focus>
        </p>
        <p>
            <input type="text">
        </p>
        <p>
            <input type="text">
        </p>
        <img v-mybind:src="img" style="width: 100px;height: 100px;">
        <input type="button" value="修改图片" @click="changeImg">
    </div>
</body>

</html>
<script src="./js/vue2.js"></script>
<script>

    // // 简写：以下写法相当于 bind + update
    // Vue.directive("mybind",function(el,binding){
    //     el[binding.arg] = binding.value;
    // })

    let vm = new Vue({
        el: "#app",
        data: {
            img: "./imgs/1.jpg"
        },
        methods: {
            changeImg() {
                this.img = "./imgs/b01.jpg"
            }
        },
        directives: {
            focus: {
                inserted: function (el, binding) {
                    el.focus();
                }
            },
            // mybind: {
            //     bind(el, binding) {
            //         el[binding.arg] = binding.value;
            //     },
            //     update: function (el, binding) {
            //         el[binding.arg] = binding.value;
            //     }
            // }
            mybind:function(el, binding) {
                    el[binding.arg] = binding.value;
            }
        }
    });







</script>